from pymongo import MongoClient


class MyMongo():

    # __instant = None
    #
    # def __new__(cls, *args, **kwargs):
    #
    #     pass


    def __init__(self, database_name, gather_name, host="127.0.0.1", port=27017):
        # 链接数据
        self.client = MongoClient(host, port)

        self.database_name = database_name
        self.gather_name = gather_name
        #
        self.work = self.client[self.database_name][self.gather_name]

    def add_data(self, data_list):
        for i in data_list:
            self.work.insert(i)

    def jquery_all(self):
        '''获取所有的文档'''
        return self.work.find()

    # def jquery_an(self, num):
    #     '''返回可以整除num的文档'''
    #     ret = self.work.find({
    #         "$where": "function(){return this._id %% %s==0 && this._id != 0;}" % num
    #     })

        # return ret

if __name__ == '__main__':

    m = MyMongo("new_python","work")

    # ret = m.jquery_an(100)
    #
    # for i in ret:
    #     print(i)
